// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]
#![no_implicit_prelude]
extern crate bytes;
extern crate serde;
extern crate serde_json;
extern crate serde_with;
extern crate std;
extern crate wkt;

mod debug;
mod deserialize;
mod serialize;

/// A common proto for logging HTTP requests. Only contains semantics
/// defined by the HTTP specification. Product-specific logging
/// information MUST be defined in a separate message.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct HttpRequest {
    /// The request method. Examples: `"GET"`, `"HEAD"`, `"PUT"`, `"POST"`.
    pub request_method: std::string::String,

    /// The scheme (http, https), the host name, the path and the query
    /// portion of the URL that was requested.
    /// Example: ``http://example.com/some/info?color=red``.
    pub request_url: std::string::String,

    /// The size of the HTTP request message in bytes, including the request
    /// headers and the request body.
    pub request_size: i64,

    /// The response code indicating the status of response.
    /// Examples: 200, 404.
    pub status: i32,

    /// The size of the HTTP response message sent back to the client, in bytes,
    /// including the response headers and the response body.
    pub response_size: i64,

    /// The user agent sent by the client. Example:
    /// `"Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461; .NET
    /// CLR 1.0.3705)"`.
    pub user_agent: std::string::String,

    /// The IP address (IPv4 or IPv6) of the client that issued the HTTP
    /// request. This field can include port information. Examples:
    /// `"192.168.1.1"`, `"10.0.0.1:80"`, `"FE80::0202:B3FF:FE1E:8329"`.
    pub remote_ip: std::string::String,

    /// The IP address (IPv4 or IPv6) of the origin server that the request was
    /// sent to. This field can include port information. Examples:
    /// `"192.168.1.1"`, `"10.0.0.1:80"`, `"FE80::0202:B3FF:FE1E:8329"`.
    pub server_ip: std::string::String,

    /// The referer URL of the request, as defined in
    /// [HTTP/1.1 Header Field
    /// Definitions](https://datatracker.ietf.org/doc/html/rfc2616#section-14.36).
    pub referer: std::string::String,

    /// The request processing latency on the server, from the time the request was
    /// received until the response was sent.
    pub latency: std::option::Option<wkt::Duration>,

    /// Whether or not a cache lookup was attempted.
    pub cache_lookup: bool,

    /// Whether or not an entity was served from cache
    /// (with or without validation).
    pub cache_hit: bool,

    /// Whether or not the response was validated with the origin server before
    /// being served from cache. This field is only meaningful if `cache_hit` is
    /// True.
    pub cache_validated_with_origin_server: bool,

    /// The number of HTTP response bytes inserted into cache. Set only when a
    /// cache fill was attempted.
    pub cache_fill_bytes: i64,

    /// Protocol used for the request. Examples: "HTTP/1.1", "HTTP/2", "websocket"
    pub protocol: std::string::String,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl HttpRequest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [request_method][crate::model::HttpRequest::request_method].
    pub fn set_request_method<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.request_method = v.into();
        self
    }

    /// Sets the value of [request_url][crate::model::HttpRequest::request_url].
    pub fn set_request_url<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.request_url = v.into();
        self
    }

    /// Sets the value of [request_size][crate::model::HttpRequest::request_size].
    pub fn set_request_size<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
        self.request_size = v.into();
        self
    }

    /// Sets the value of [status][crate::model::HttpRequest::status].
    pub fn set_status<T: std::convert::Into<i32>>(mut self, v: T) -> Self {
        self.status = v.into();
        self
    }

    /// Sets the value of [response_size][crate::model::HttpRequest::response_size].
    pub fn set_response_size<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
        self.response_size = v.into();
        self
    }

    /// Sets the value of [user_agent][crate::model::HttpRequest::user_agent].
    pub fn set_user_agent<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.user_agent = v.into();
        self
    }

    /// Sets the value of [remote_ip][crate::model::HttpRequest::remote_ip].
    pub fn set_remote_ip<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.remote_ip = v.into();
        self
    }

    /// Sets the value of [server_ip][crate::model::HttpRequest::server_ip].
    pub fn set_server_ip<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.server_ip = v.into();
        self
    }

    /// Sets the value of [referer][crate::model::HttpRequest::referer].
    pub fn set_referer<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.referer = v.into();
        self
    }

    /// Sets the value of [latency][crate::model::HttpRequest::latency].
    pub fn set_latency<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<wkt::Duration>,
    {
        self.latency = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [latency][crate::model::HttpRequest::latency].
    pub fn set_or_clear_latency<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<wkt::Duration>,
    {
        self.latency = v.map(|x| x.into());
        self
    }

    /// Sets the value of [cache_lookup][crate::model::HttpRequest::cache_lookup].
    pub fn set_cache_lookup<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
        self.cache_lookup = v.into();
        self
    }

    /// Sets the value of [cache_hit][crate::model::HttpRequest::cache_hit].
    pub fn set_cache_hit<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
        self.cache_hit = v.into();
        self
    }

    /// Sets the value of [cache_validated_with_origin_server][crate::model::HttpRequest::cache_validated_with_origin_server].
    pub fn set_cache_validated_with_origin_server<T: std::convert::Into<bool>>(
        mut self,
        v: T,
    ) -> Self {
        self.cache_validated_with_origin_server = v.into();
        self
    }

    /// Sets the value of [cache_fill_bytes][crate::model::HttpRequest::cache_fill_bytes].
    pub fn set_cache_fill_bytes<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
        self.cache_fill_bytes = v.into();
        self
    }

    /// Sets the value of [protocol][crate::model::HttpRequest::protocol].
    pub fn set_protocol<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.protocol = v.into();
        self
    }
}

impl wkt::message::Message for HttpRequest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.logging.type.HttpRequest"
    }
}

/// The severity of the event described in a log entry, expressed as one of the
/// standard severity levels listed below.  For your reference, the levels are
/// assigned the listed numeric values. The effect of using numeric values other
/// than those listed is undefined.
///
/// You can filter for log entries by severity.  For example, the following
/// filter expression will match log entries with severities `INFO`, `NOTICE`,
/// and `WARNING`:
///
/// ```norust
/// severity > DEBUG AND severity <= WARNING
/// ```
///
/// If you are writing log entries, you should map other severity encodings to
/// one of these standard levels. For example, you might map all of Java's FINE,
/// FINER, and FINEST levels to `LogSeverity.DEBUG`. You can preserve the
/// original severity level in the log entry payload if you wish.
///
/// # Working with unknown values
///
/// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
/// additional enum variants at any time. Adding new variants is not considered
/// a breaking change. Applications should write their code in anticipation of:
///
/// - New values appearing in future releases of the client library, **and**
/// - New values received dynamically, without application changes.
///
/// Please consult the [Working with enums] section in the user guide for some
/// guidelines.
///
/// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum LogSeverity {
    /// (0) The log entry has no assigned severity level.
    Default,
    /// (100) Debug or trace information.
    Debug,
    /// (200) Routine information, such as ongoing status or performance.
    Info,
    /// (300) Normal but significant events, such as start up, shut down, or
    /// a configuration change.
    Notice,
    /// (400) Warning events might cause problems.
    Warning,
    /// (500) Error events are likely to cause problems.
    Error,
    /// (600) Critical events cause more severe problems or outages.
    Critical,
    /// (700) A person must take an action immediately.
    Alert,
    /// (800) One or more systems are unusable.
    Emergency,
    /// If set, the enum was initialized with an unknown value.
    ///
    /// Applications can examine the value using [LogSeverity::value] or
    /// [LogSeverity::name].
    UnknownValue(log_severity::UnknownValue),
}

#[doc(hidden)]
pub mod log_severity {
    #[allow(unused_imports)]
    use super::*;
    #[derive(Clone, Debug, PartialEq)]
    pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
}

impl LogSeverity {
    /// Gets the enum value.
    ///
    /// Returns `None` if the enum contains an unknown value deserialized from
    /// the string representation of enums.
    pub fn value(&self) -> std::option::Option<i32> {
        match self {
            Self::Default => std::option::Option::Some(0),
            Self::Debug => std::option::Option::Some(100),
            Self::Info => std::option::Option::Some(200),
            Self::Notice => std::option::Option::Some(300),
            Self::Warning => std::option::Option::Some(400),
            Self::Error => std::option::Option::Some(500),
            Self::Critical => std::option::Option::Some(600),
            Self::Alert => std::option::Option::Some(700),
            Self::Emergency => std::option::Option::Some(800),
            Self::UnknownValue(u) => u.0.value(),
        }
    }

    /// Gets the enum value as a string.
    ///
    /// Returns `None` if the enum contains an unknown value deserialized from
    /// the integer representation of enums.
    pub fn name(&self) -> std::option::Option<&str> {
        match self {
            Self::Default => std::option::Option::Some("DEFAULT"),
            Self::Debug => std::option::Option::Some("DEBUG"),
            Self::Info => std::option::Option::Some("INFO"),
            Self::Notice => std::option::Option::Some("NOTICE"),
            Self::Warning => std::option::Option::Some("WARNING"),
            Self::Error => std::option::Option::Some("ERROR"),
            Self::Critical => std::option::Option::Some("CRITICAL"),
            Self::Alert => std::option::Option::Some("ALERT"),
            Self::Emergency => std::option::Option::Some("EMERGENCY"),
            Self::UnknownValue(u) => u.0.name(),
        }
    }
}

impl std::default::Default for LogSeverity {
    fn default() -> Self {
        use std::convert::From;
        Self::from(0)
    }
}

impl std::fmt::Display for LogSeverity {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
        wkt::internal::display_enum(f, self.name(), self.value())
    }
}

impl std::convert::From<i32> for LogSeverity {
    fn from(value: i32) -> Self {
        match value {
            0 => Self::Default,
            100 => Self::Debug,
            200 => Self::Info,
            300 => Self::Notice,
            400 => Self::Warning,
            500 => Self::Error,
            600 => Self::Critical,
            700 => Self::Alert,
            800 => Self::Emergency,
            _ => Self::UnknownValue(log_severity::UnknownValue(
                wkt::internal::UnknownEnumValue::Integer(value),
            )),
        }
    }
}

impl std::convert::From<&str> for LogSeverity {
    fn from(value: &str) -> Self {
        use std::string::ToString;
        match value {
            "DEFAULT" => Self::Default,
            "DEBUG" => Self::Debug,
            "INFO" => Self::Info,
            "NOTICE" => Self::Notice,
            "WARNING" => Self::Warning,
            "ERROR" => Self::Error,
            "CRITICAL" => Self::Critical,
            "ALERT" => Self::Alert,
            "EMERGENCY" => Self::Emergency,
            _ => Self::UnknownValue(log_severity::UnknownValue(
                wkt::internal::UnknownEnumValue::String(value.to_string()),
            )),
        }
    }
}

impl serde::ser::Serialize for LogSeverity {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        match self {
            Self::Default => serializer.serialize_i32(0),
            Self::Debug => serializer.serialize_i32(100),
            Self::Info => serializer.serialize_i32(200),
            Self::Notice => serializer.serialize_i32(300),
            Self::Warning => serializer.serialize_i32(400),
            Self::Error => serializer.serialize_i32(500),
            Self::Critical => serializer.serialize_i32(600),
            Self::Alert => serializer.serialize_i32(700),
            Self::Emergency => serializer.serialize_i32(800),
            Self::UnknownValue(u) => u.0.serialize(serializer),
        }
    }
}

impl<'de> serde::de::Deserialize<'de> for LogSeverity {
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        deserializer.deserialize_any(wkt::internal::EnumVisitor::<LogSeverity>::new(
            ".google.logging.type.LogSeverity",
        ))
    }
}
